<template>
  <div class="app-container">
    <!-- 高级查询 -->
    <el-form v-show="searchVisible" ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item label="订单号:">
        <el-input v-model="queryParams.salesOrderNo" size="small" placeholder="请输入订单号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 数据列表 -->
    <el-table v-loading="loading" :data="list" highlight-current-row @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="订单号" align="center" width="180">
        <template slot-scope="scope">
          <span>{{ scope.row.variables.map.title }}</span>
        </template>
      </el-table-column>
      <el-table-column label="当前审核节点" align="center" prop="taskName" />
      <el-table-column label="审核流程名称" align="center" prop="procName" />
      <el-table-column label="审核流程版本" align="center" prop="version" />
      <el-table-column label="提交审核时间" align="center" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button v-if="scope.row.assignee" size="mini" type="text" @click="handleAudit(scope.row)">审核</el-button>
          <el-button v-else size="mini" type="text" @click="handleClaim(scope.row.taskId)">签收任务</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import SalesOrderApi from '@/api/order/SalesOrderApi'
import TaskApi from '@/api/activiti/TaskApi'

export default {
  name: 'SalesOrderAuditingList',
  data() {
    return {
      options: {
      },
      queryParams: {
        salesOrderNo: null
      },
      list: [],
      loading: true,
      searchVisible: true,
      multipleSelection: [],
      isSingle: true,
      isMultiple: true
    }
  },
  created() {
    this.handleQuery()
  },
  methods: {
    loadOptions() {
    },
    handleClaim(taskId) {
      this.$confirm('是否确认签收任务?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return TaskApi.claim(taskId)
      }).then(() => {
        this.handleQuery()
        this.$message.success('签收成功')
      })
    },
    handleAudit(row) {
      this.$router.push({
        path: '/salesOrder/audit',
        query: {
          procInsId: row.procInsId,
          taskId: row.taskId,
          taskDefKey: row.taskDefKey
        }
      })
    },
    handleQuery() {
      this.loading = true
      SalesOrderApi.auditingList().then(response => {
        this.list = response.data
        this.loading = false
      }, () => {
        this.loading = false
      })
    },
    handleSelectionChange(selection) {
      this.multipleSelection = selection
      this.isSingle = selection.length !== 1
      this.isMultiple = !selection.length
    },
    resetQuery() {
      this.page.current = 1
      this.resetForm('queryForm')
      this.handleQuery()
    }
  }
}
</script>
